package org.example.controller;

import org.example.entity.BlockchainRecord;
import org.example.service.BlockchainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/blockchain")
public class BlockchainController {

    @Autowired
    private BlockchainService blockchainService;

    // 获取所有区块链记录
    @GetMapping
    public List<BlockchainRecord> getAllBlockchainRecords() {
        return blockchainService.getAllBlockchainRecords();
    }

    // 根据ID获取区块链记录
    @GetMapping("/{id}")
    public BlockchainRecord getBlockchainRecordById(@PathVariable Integer id) {
        return blockchainService.getBlockchainRecordById(id);
    }

    // 根据交易哈希获取区块链记录
    @GetMapping("/transaction")
    public BlockchainRecord getBlockchainRecordByTransactionHash(@RequestParam String transactionHash) {
        return blockchainService.getBlockchainRecordByTransactionHash(transactionHash);
    }

    // 添加区块链记录
    @PostMapping
    public void addBlockchainRecord(@RequestBody BlockchainRecord record) {
        blockchainService.addBlockchainRecord(record);
    }
}

